package moe.bogos.douro.api.common.entity;

import moe.bogos.douro.api.common.soul.skill.Skill;
//import moe.bogos.douro.api.common.soul.SoulRing;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.IPacket;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.DamageSource;
import net.minecraft.util.Hand;
import net.minecraft.util.math.vector.Vector4f;
import net.minecraft.world.World;
import net.minecraftforge.fml.network.NetworkHooks;

public class SoulRingDropEntity extends Entity
{
    // int x = 0;
    private PlayerEntity followedPlayer;
    private DamageSource damageSource;
    //private LightWrapper wrapper;
    //private LightInfo info;
    //private SoulRing soulRing;
    private boolean isFollowingPlayer;
    //private double x = 0;

    public SoulRingDropEntity(EntityType<?> entityTypeIn, World worldIn)
    {
        this(entityTypeIn, worldIn, "");
    }
    
    public SoulRingDropEntity(EntityType<?> entityTypeIn, World worldIn, String soulBeastName)
    {
        this(entityTypeIn, worldIn, soulBeastName, new Skill[0]);
    }
    
    public SoulRingDropEntity(EntityType<?> entityTypeIn, World worldIn, String soulBeastName, Skill... skills)
    {
        this(entityTypeIn, worldIn, 0, soulBeastName, skills);
    }
    
    public SoulRingDropEntity(EntityType<?> entityTypeIn, World worldIn, int age, String soulBeastName, Skill... skills)
    {
        this(entityTypeIn, worldIn, age, null, soulBeastName, null, skills);
    }

    public SoulRingDropEntity(EntityType<?> entityTypeIn, World worldIn, int age, String soulBeastName, DamageSource source, Skill... skills)
    {
        this(entityTypeIn, worldIn, age, null, soulBeastName, source, skills);
    }

    public SoulRingDropEntity(EntityType<?> entityTypeIn, World worldIn, int age, PlayerEntity followedPlayer, String soulBeastName, DamageSource source, Skill... skills)
    {
        super(entityTypeIn, worldIn);
        this.followedPlayer = followedPlayer;
        this.damageSource = source;
        //this.setSize(0.5f, 0.5f);
        /*if (worldIn.isRemote)
        {
            this.wrapper = new LightWrapper(worldIn);
            info = wrapper.setLight(14, posX, posY, posZ);
        }
        worldIn.setBlockState(new BlockPos(posX, posY, posZ), Blocks.AIR.getDefaultState());*/
        //soulRing = new SoulRing(age, soulBeastName, skills);
    }

    @Override
    protected void defineSynchedData()
    {

    }

    @Override
    protected void readAdditionalSaveData(CompoundNBT p_70037_1_)
    {
        //soulRing = new SoulRing(compound.getCompound(Constants.SOUL_DATA));
    }

    @Override
    protected void addAdditionalSaveData(CompoundNBT p_213281_1_)
    {
        //compound.put(Constants.SOUL_DATA, soulRing.writeToNbt());
    }

    @Override
    public IPacket<?> getAddEntityPacket()
    {
        return NetworkHooks.getEntitySpawningPacket(this);
    }

    /*
    public PlayerEntity getFollowedPlayer()
    {
        return followedPlayer;
    }
    */
    
    public int getAge()
    {
        return 0;//TODO
    }
    
    public Vector4f getColor()
    {
        Vector4f color = null;
        if (getAge() <= 100)
            color = new Vector4f(1.0f, 1.0f, 1.0f, 0.7f);
        else if (getAge() > 100 && getAge() <= 1000)
            color = new Vector4f(238f / 255f, 199f / 255f, 16f / 255f, 0.7f);
        else if (getAge() > 1000 && getAge() <= 10000)
            color = new Vector4f(128f / 255f, 0f / 255f, 255f / 255f, 0.7f);
        else if (getAge() > 10000 && getAge() <= 100000)
            color = new Vector4f(0f / 255f, 0f / 255f, 0f / 255f, 0.7f);
        else if (getAge() > 10000 && getAge() <= 1000000)
            color = new Vector4f(255f / 255f, 0f / 255f, 0f / 255f, 0.7f);
        return color;
    }

    @Override
    public ActionResultType interact(PlayerEntity player, Hand hand)
    {
//    	isFollowingPlayer = false;
//        BlockPos pos = player.getPosition();
//    	if(isFollowingPlayer = false)
//    	{
//    		player.openGui(DouroAPI.instance, modGuiId, world, x, y, z);
//    	}
        return ActionResultType.PASS;
    }

    public boolean shouldRenderInPass(int pass)
    {
        // TODO: Find 1.16.5 replacement
        return pass == 1;
    }

    public DamageSource getDamageSource()
    {
        return damageSource;
    }
}
